<?php
/**
 * Name: FileUploadController.class.php
 * Description: 文件上传
 * User: DIY
 * Date: 2016/9/9
 * Time: 15:22
 */

namespace Security\Controller;

use Think\Controller;
use Think\Upload;

class FileUploadController extends Controller
{
    /*
     * 图片上传
     * 上传文件file名称必须是images
     * return array(status,msg,path)
     * */
    public function image(){
        //文件上传限制
        $config = array(
            'maxSize'    =>    C('UPLOAD_FILE_MAX'),//2M
            'rootPath'   =>    $_SERVER['DOCUMENT_ROOT'],
            'savePath'   =>    '/Public/Upload/',
            'saveName'   =>    array('uniqid',''),
            'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),
            'autoSub'    =>    true,
            'subName'    =>    array('date','Ymd'),
        );
        $Upload = new Upload($config);
        $info = $Upload->uploadOne($_FILES['images']);
        if(!$info) {// 上传错误提示错误信息
            $this->ajaxReturn(array('status'=>'99','msg'=>$Upload->getError()));
        }else{
            // 上传成功获取上传文件信息
            $path =  $info['savepath'].$info['savename'];
            $this->ajaxReturn(array('status'=>'100','msg'=>'上传成功','path'=>$path));
        }
    }

}